package com.zsy.controller;

import com.zsy.pojo.Clazz;
import com.zsy.pojo.ClazzQueryParam;
import com.zsy.pojo.PageResult;
import com.zsy.pojo.Result;
import com.zsy.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: zhengsuyang
 * @Desc:
 * @create: 2025-09-11 09:27
 **/
@RestController
@RequestMapping("/clazzs")
@Slf4j
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    /**
     * 分页 + 条件查询
     * @param clazzQueryParam
     * @return
     */
    @GetMapping
    public Result queryPageClazz(ClazzQueryParam clazzQueryParam){
       PageResult<Clazz> pageResult =  clazzService.clazzQueryParam(clazzQueryParam);
       return Result.success(pageResult);
    }

    /**
     * 根据id查询班级
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result queryClazzById(@PathVariable Integer id){
        Clazz clazz = clazzService.queryClazzById(id);
        return Result.success(clazz);
    }
    /**
     * 新增班级
     * @param clazz
     * @return
     */
    @PostMapping
    public Result addClazz(@RequestBody Clazz clazz){
        clazzService.addClazz(clazz);
        return Result.success();
    }

    /**
     * 修改班级
     * @param clazz
     * @return
     */
    @PutMapping
    public Result updateClazz(@RequestBody Clazz clazz){
        clazzService.updateClazz(clazz);
        return Result.success();
    }
}
